package com.ecocent.api;

import java.io.IOException;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ecocent.api.helper.ClasspathResourceScanner;

final class ApiProviderNotifier {
	private static final Logger LOG = LoggerFactory.getLogger(ApiProviderNotifier.class);
	private ApiContext apiContext;
	public ApiProviderNotifier(ApiContext apiContext)
	{
		this.apiContext = apiContext;
	}
	public void notifyProvider()
	{
		try {
			List<Class> serivces = ClasspathResourceScanner.findConfiguredImplementations(ApiServiceProvider.class,"/META-INF/config-spi.properties");
			 for (Class p : serivces) {
	                try {
	                    ((ApiServiceProvider)p.newInstance()).notify(apiContext);
	                } catch (Exception e) {
	                    LOG.warn("Unable to instantiate apiServiceProvider for class " + p.getName());
	                }
	            }
		} catch (IOException e) {
			LOG.error("An error occurs during classpath scanning", e);
		}
	}

}
